package com.jsfcompref.solutech.backing;


import com.eCommerce.corecontract.dto.CategorieDTO;
import com.eCommerce.corecontract.dto.ComposantDTO;
import com.eCommerce.corecontract.exception.EcommerceException;
import com.eCommerce.server.corebackend.util.BackEndConstants;
import com.eCommercecorecontract.svco.ICategorieSVCO;
import com.eCommercecorecontract.svco.IComposantSVCO;
import com.eCommercecorecontract.svco.SVCOFinder;
import com.ecommerceWeb.common.ServiceFinder;
import com.ecommerceWeb.common.JSFUtil;
import com.jsfcompref.solutech.model.PanierAchatBean;

import java.util.List;

import javax.faces.application.Application;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;



public class Composants {
	
	//modif

	 public Composants() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	
	private UIData data = null;
	

	public UIData getData() {
		return data;
	}

	public void setData(UIData data) {
		this.data = data;
	}

	public List getComposants()
	  {		
			List cmps = null;
			try {
				
				FacesContext ctx = FacesContext.getCurrentInstance();
				Application app = ctx.getApplication();
				CategorieDTO categorie = (CategorieDTO)JSFUtil.getManagedObject("GetCategorie");
				
				SVCOFinder sVCOFinder=(SVCOFinder) ServiceFinder.findBean("SVCOFinder");
				IComposantSVCO composantSVCO=(IComposantSVCO)sVCOFinder.get(BackEndConstants.SVCO_COMPOSANT);
				ICategorieSVCO categorieSVCO =(ICategorieSVCO)sVCOFinder.get(BackEndConstants.SVCO_CATEGORIE);
				categorie = categorieSVCO.visualiserCategorie(categorie);
				
				cmps = composantSVCO.rechercherComposantParCategorie(categorie);
				
				} catch (EcommerceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		
	  return cmps;
	  }
	
	public String getComposantDetailsAction(){
		
		ComposantDTO selectedComposant = (ComposantDTO) this.getData().getRowData();
		FacesContext ctx = FacesContext.getCurrentInstance();
		ctx.getExternalContext().getSessionMap().put("GetComposant", selectedComposant);
		
		return "succes";
	}
	

 
}
